package com.chaodev.base.controller;

import com.chaodev.base.dto.LearningRecordDto;
import com.chaodev.base.model.Result;
import com.chaodev.base.service.LearningRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("learningRecord")
@Api(tags = "课程学习记录相关接口")
public class LearningRecordController {
    @Autowired
    private LearningRecordService learningRecordService;

    @GetMapping("/training")
    @ApiOperation(value = "查询学习记录")
    public Result queryLearningRecord(Integer trainingId,
                                      @DateTimeFormat(pattern = "yyyy-MM-ddHH:mm:ss") String startTime,
                                      @DateTimeFormat(pattern = "yyyy-MM-ddHH:mm:ss") String commitTime,
                                      Integer page,Integer rows,
                                      HttpServletRequest request) {
        return learningRecordService.queryLearningRecord(trainingId, startTime, commitTime, request,page,rows);

    }

    @PostMapping("addRecord")
    @ApiOperation(value = "提交学习记录")
    public Result addRecord(@RequestBody @Validated LearningRecordDto dto, HttpServletRequest request) {
        return learningRecordService.addLearningRecord(dto, request);
    }

}
